[ADF tip #1] Working around some clientListener limitation

Posted by julien.schneider(at)oracle.com on Oracle Blogs See other posts from Oracle Blogs or by julien.schneider(at)oracle.com
Published on Wed, 16 Mar 2011 21:26:36 +0100 Indexed on 2011/03/17 0:15 UTC
Read the original article Hit count: 313

Filed under:

As i occasionally work on Oracle ADF, i've decided to write tips on this Framework.

Previous version of adf (10g) had a <afh:body> component to represent the body of your page which allowed to specify javascript events like onload or onunload.

In ADF RC, the body (as well as html and head) is geneated by a single <af:document>.

To implement the onXXXXX events you embed an <af:clientListener> within this <af:document> and specify property type="load" with the method to trigger.

 

Problem is that onunload property is not supported by th af:clientListener. So how do i do ?

Well, a solution is to add this event during page load.

 

First step :

Embed in your <af:document> the following :

<af:clientListener type="load" method="addOnUnload()"/>

 

Second step :

Add your unload event using this kind of script :

<af:document>
    <f:facet name="metaContainer">

    <f:verbatim>
    <script type="text/javascript">    
            function
addOnUnload
(evt) {
                      window.
onunload
=function()
                              {

                                  alert('Goodbye Word');
                              }
                   }

    </script>
    </f:verbatim>

 

When closing browser your event will be triggered as expected.

 

 

goodbye.PNG

© Oracle Blogs or respective owner